package freespiritsocial.io.user.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.bean.UserInfo
import freespiritsocial.io.user.data.model.bean.UserInfo.Companion.STATUS_ADD
import freespiritsocial.io.user.data.model.bean.UserInfo.Companion.STATUS_DEL
import freespiritsocial.io.user.databinding.ItemFollowedBinding
import java.util.*

/**
 * 已关注的列表
 */
class FollowedAdapter(
    data: ArrayList<UserInfo> = arrayListOf(),
    layoutResIdRes: Int = R.layout.item_followed
):
    BaseQuickAdapter<UserInfo,BaseDataBindingHolder<ItemFollowedBinding>>(layoutResIdRes,data) {

    override fun convert(holder: BaseDataBindingHolder<ItemFollowedBinding>,item: UserInfo) {
        holder.dataBinding?.user = item
    }

    fun dealData(userInfo: UserInfo) {
        // TODO: 2021/11/21 分事件处理用户
        when (userInfo.eventStatus) {
            STATUS_ADD -> data.find { it.userId == userInfo.userId } ?: addData(userInfo)
            STATUS_DEL -> remove(userInfo)
        }
    }
}